<?php
//店铺导航
// +----------------------------------------------------------------------
// | TAODUDU.COM  [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.taodudu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: ubten <462193409@qq.com> http://www.ubten.com/
// +----------------------------------------------------------------------

namespace Store\Controller;
use Store\Controller\StoreController;
class NavigationController extends StoreController {
    //put your code here
    function _initialize() {
        parent::_initialize();
        $this->assign('sys','set');// 数据集

    }
    
    
    public function index(){

        $pMan = D('storeNavigation');
        $count = $pMan->where(array("sn_store_id" =>session('store_id')))->order('sn_id desc')->count();//获得满足条件的记录数
        $Page  = new \Think\Page($count,10);//实例化分页类 传入总记录数和每页显示的记录数(10)
        $show  = $Page->show();// 分页显示输出
        $list = $pMan->where(array("sn_store_id" =>session('store_id')))->order('sn_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);// 数据集
        $this->assign('page',$show);// 页码
        $this->assign('action','navigation');
        $this->display();
        
    }
    
    
    public function add(){
        
        if(IS_POST){
            $data['sn_title'] = I('sn_title');
            $data['sn_store_id'] = session('store_id');
            $data['sn_sort'] = I('sn_sort');
            $data['sn_if_show'] = I('sn_if_show');
            $data['sn_add_time'] = NOW_TIME;
            $data['sn_url'] = I('sn_url');
            $data['sn_new_open'] = I('sn_new_open');
            $re = M('storeNavigation')->add($data);
            if($re){
                $this->success('导航添加成功！',U('index'));
            }else{
                $this->error('导航添加失败！');
            }
        }
        $this->assign('action','navigation');
        $this->display();
    }
    
    
    public function edit(){
        $sn_id = I('sn_id');
        $map['sn_id'] = $sn_id;
        if(IS_POST){
            $data['sn_title'] = I('sn_title');
            $data['sn_store_id'] = session('store_id');
            $data['sn_sort'] = I('sn_sort');
            $data['sn_if_show'] = I('sn_if_show');
            $data['sn_url'] = I('sn_url');
            $data['sn_new_open'] = I('sn_new_open');
            $re = M('storeNavigation')->where($map)->save($data);
            if($re){
                $this->success('导航修改成功！',U('index'));
            }else{
                $this->error('导航修改失败！');
            }
        }
        $re = M('storeNavigation')->where($map)->find();
        $this->assign('re',$re);
        $this->assign('action','navigation');
        $this->display();
    }
    
    
    public function del(){
        
        $this->display();
    }
    
    
}
